#!/bin/bash
hops=$1

#cat Location$hops-1 Location$hops-2 Location$hops-3 Location$hops-4 Location$hops-5 Location$hops-6 Location$hops-7 Location$hops-8 Location$hops-9 Location$hops-10 >> Location$hopsTotal
#awk '{print $4 " " $6}' Location$hops-Total > Location2

while read line1 
do 
	array1=(${line1// / })
	pos1x=$(echo ${array1[0]} | tr ':' ' ' | awk '{print $1}')
	pos1y=$(echo ${array1[0]} | tr ':' ' ' | awk '{print $2}')
	pos2x=$(echo ${array1[1]} | tr ':' ' ' | awk '{print $1}')
	pos2y=$(echo ${array1[1]} | tr ':' ' ' | awk '{print $2}')

	echo $pos1x $pos1y
	echo $pos2x $pos2y
	difx=$(expr $pos2x - $pos1x)
	dify=$(expr $pos2y - $pos1y)
	echo $difx $dify
	q1=$(expr $difx \* $difx)
	q2=$(expr $dify \* $dify)
	echo $q1 $q2
	sum=$(expr $q1 + $q2)
	echo $sum
	error=$(echo "sqrt($sum)" | bc)
	echo $error >> FileAux

done < Location2

somatorio=$(cat FileAux | awk '{sum+=$1} END {print sum}')
number=$(cat FileAux | wc -l < FileAux)
media=$(expr $somatorio / $number )
echo "Média = " $media
echo $media >> AverageError2


